<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/20 0020
 * Time: 上午 11:01
 */
namespace app\admin\controller;

use app\common\controller\Curt;
class Area extends Curt {

    public function getall()
    {
        $keyword=input('get.keyword');
        if($keyword){
            $where['a_name|b.p_name|c.c_name']=['like','%'.$keyword.'%'];
        }
        $alias=['ec_area'=>'a','ec_province'=>'b','ec_city'=>'c'];//传入数组批量设置数据表以及别名
        $join = [
            ['ec_province','a.p_id=b.id', ],
            ['ec_city','a.c_id=c.id', ],
        ];
        $list = $this->model ->alias($alias) ->join($join) ->order('id desc') ->where($where) ->field("a.*,b.p_name,c.c_name") ->paginate();
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
    }
    public function add()
    {
        $data=$this->request->param();
        $validate=validate($this->table);
        if(!$validate->check($data)){
            $this->error($validate->getError());
        }
        $data=$this->adddatabefter($data);
        $res=$this->model->allowField(true)->save($data);
        if($res){
            $this->success('添加成功',url('city/showlist'));
        }else{
            $this->error('添加失败');
        }
    }

}